package com.lingyu.jsjx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.lingyu.jsjx.domain.UserDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.lingyu.jsjx.domain.DocumentRecommend;
import com.lingyu.jsjx.service.IDocumentRecommendService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 推荐Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/documentRecommend")
public class DocumentRecommendController extends BaseController
{
    @Autowired
    private IDocumentRecommendService documentRecommendService;

    /**
     * 查询推荐列表
     */
    @RequiresPermissions("jsjx:documentRecommend:list")
    @GetMapping("/list")
    public TableDataInfo list(UserDocument userDocument)
    {
        startPage();
        List<DocumentRecommend> list = documentRecommendService.selectDocumentRecommendList(userDocument);
        return getDataTable(list);
    }

    /**
     * 导出推荐列表
     */
    @RequiresPermissions("jsjx:documentRecommend:export")
    @Log(title = "推荐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserDocument userDocument)
    {
        List<DocumentRecommend> list = documentRecommendService.selectDocumentRecommendList(userDocument);
        ExcelUtil<DocumentRecommend> util = new ExcelUtil<DocumentRecommend>(DocumentRecommend.class);
        util.exportExcel(response, list, "推荐数据");
    }

    /**
     * 获取推荐详细信息
     */
    @RequiresPermissions("jsjx:documentRecommend:query")
    @GetMapping(value = "/{recommendId}")
    public AjaxResult getInfo(@PathVariable("recommendId") Long recommendId)
    {
        return success(documentRecommendService.selectDocumentRecommendByRecommendId(recommendId));
    }

    /**
     * 新增推荐
     */
    @RequiresPermissions("7")
    @Log(title = "推荐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocumentRecommend documentRecommend)
    {
        return toAjax(documentRecommendService.insertDocumentRecommend(documentRecommend));
    }

    /**
     * 修改推荐
     */
    @RequiresPermissions("jsjx:documentRecommend:edit")
    @Log(title = "推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocumentRecommend documentRecommend)
    {
        return toAjax(documentRecommendService.updateDocumentRecommend(documentRecommend));
    }

    /**
     * 删除推荐
     */
    @RequiresPermissions("jsjx:documentRecommend:remove")
    @Log(title = "推荐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recommendIds}")
    public AjaxResult remove(@PathVariable Long[] recommendIds)
    {
        return toAjax(documentRecommendService.deleteDocumentRecommendByRecommendIds(recommendIds));
    }
}
